#include<iostream>
#include<thread>
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>


using namespace std;

class TA{
    public:
    int &subi;
    TA(int &aa):subi(aa){};
    // ~TA(){
    //     subi = 1;
    // }
    void operator()(){
        cout<<"sub begin..."<<subi<<endl;
        // this_thread::sleep_for(chrono::microseconds(200));
        
        for (size_t i = 0; i < 10; i++)
        {
            cout<<"sub开始循环 "<<i <<" = "<<subi<<endl;
            // sleep(1);
            this_thread::sleep_for(chrono::microseconds(10));

            if(i==3) subi= 3;
        }
        
        cout<<"sub end..."<<subi<<endl;
    }
};

int main(int argc,char **argv){

    int mi = 4;
   TA ta(mi);
   cout<<"main first ta ="<<ta.subi<<endl;
//    ta();
   thread td(ta);
   cout<<"main begin..."<<mi<<endl;
    for (size_t ii = 0; ii < 10; ii++)
    {
        cout<<"main开始循环 "<<ii<<" = "<<mi<<endl;
        this_thread::sleep_for(chrono::microseconds(10));

    }
   getchar();
//    if(td.joinable())td.join();

   cout<<"main end ta ="<<ta.subi<<endl;


   return 0;
}